package MagicTool_assignDecisionMaker;


import static org.junit.Assert.*;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import FamilyTherapy.MagicToolCard;
import FamilyTherapy.Player;
import FamilyTherapy.EventCard;

public class testMagicToolCard_assignDescisionMaker_2 {

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}
	
	//there is a problem in this test case that 
	//when more than 1 test case is done, it would crash the program
	//therefore we seperate them into different classes
	
	@Test
	public void testAssignDecisionMaker_2() 
	{
		//initialise variable
		int result;
		Player[] p ={new Player("a",1),new Player("b",2)};
		MagicToolCard m = new MagicToolCard();	
		EventCard e = new EventCard(0);
		
		//for output // as they are just stream, they would be stop when finish reading
		final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
		System.setOut(new PrintStream(outContent));
		//String newLine = System.getProperty("line.separator");
		
		String expected = "Now, you can assign one of the players as decision maker.\n"  +
						"Who do you want to be assigned? Please enter the player number: \n"+
						"b , player no: 1    \n" +
						"Please input an integer.\n" +
						"Choice 0 :\n" + 
						"Q1_choice 1\n"+ 
						"Choice 1 :\n" +
						"Q1_choice 2\n"+ 
						"Choice 2 :\n" +
						"Q1_choice 3\n"+
						"Choice 3 :\n" +
						"Q1_choice 4\n"+
						"b, please input your choice. Choice: \n";
		
		//data to be input 
		String data = "a 1 1"; 	
		InputStream stdin = System.in; 
		try {   
			System.setIn(new ByteArrayInputStream(data.getBytes()));	//put data to input stream
			result = m.assignDescisionMaker(e,0,p);	//for getting data from input stream
		} 
		finally {  
			System.setIn(stdin); 	//reset input stream as System.in
		}
		
		//for testing
		assertEquals(expected,outContent.toString());
		assertEquals(result, 1);
	}

}
